#ifndef __RenderingParticleSystem__h__included__
#define __RenderingParticleSystem__h__included__

#include "neiderra/math/Vectors.h"

#include <list>

using neiderra::math::vec3;

namespace neiderra {
	namespace rendering {

		class iRenderer;
		class Texture;

		// Particle
		struct Particle {
			float lifetime;	
			float size;
            vec3 pos;
			vec3 view;
			vec3 up;
			
			virtual int update(double deltaT);
			void setLifeTime(float time) { lifetime = time; }
			Particle();
			virtual ~Particle();
		};

		// particles-sprite
		struct PolyParticle : public Particle {
			vec3 poly[3];
			vec3 color;
			Texture* texture;
			PolyParticle();
			virtual ~PolyParticle();
		};

		// list of particles
		typedef std::list<Particle*> Particles;

		// Particle system
		class ParticleSystem {
		public:
			virtual Particle* add();
			virtual int remove(Particle*);
			virtual int update(double deltaT);

			virtual void render(iRenderer* r);
			
			Particles* getParticles() { return &_particles; }
			virtual unsigned getMaxParticlesNum() { return _maxParticles; }
			
			// create n particles, where n - max particles number,
			// specified by user
			virtual void initParticles()=0;

			bool isActive() { return _active; }
			
			// set max number of particles
			virtual void setMaxParticles(unsigned num){ _maxParticles = num; }
			virtual unsigned getMaxParticles() { return _maxParticles; }
			void setMaxLifetime(float t) { _time = t; }
			float getMaxLifetime() { return _time; } 

			virtual void reset() {}
		private:
			float _time;
			unsigned _maxParticles;
		protected:
			bool _active;
			//std::list<Particle*> _particles;
			Particles _particles;
		};

		// Particle system with sprite particles
		class PolyParticleSystem : public ParticleSystem{
		public:

			PolyParticleSystem();
			virtual ~PolyParticleSystem();

			virtual Particle* add();
			virtual void render(iRenderer* r);

			virtual int update(double deltaT);

			virtual void initParticles();

			virtual void setTexture(Texture* t) {_texture = t;}
			
			virtual Texture* getTexture() { return _texture; }


		protected:
			Texture* _texture;
   		};

	}
}

#endif
